<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>order管理</title>
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <!-- 引入样式 -->
    <link href="https://unpkg.com/element-ui/lib/theme-chalk/index.css" rel="stylesheet">
    <link href="../plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">

    <!-- 上传图片框样式，不使用上传组件可以删除此样式 -->
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 150px;
            height: 70px;
            line-height: 150px;
            text-align: center;
        }

        .avatar {
            width: 150px;
            height: 70px;
            display: block;
        }

    </style>
</head>
<body class="hold-transition">
<div id="app">

    <div class="content-header">
        <h1>管理<small>订单管理</small></h1>
        <el-breadcrumb class="breadcrumb" separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>确认收货</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <!--查询表单-->
                <el-form :inline="true" class="demo-form-inline">
                    <el-form-item label="输入搜索">
                        <el-input placeholder="订单编号/商品货号" v-model="searchMap.id"></el-input>
                    </el-form-item>
                    <el-form-item label="收货人">
                        <el-input placeholder="收货人姓名/手机号码" v-model="searchMap.receiverContact"></el-input>
                    </el-form-item>
                    <el-form-item label="提交时间">
                        <el-date-picker
                                :picker-options="pickerOptions"
                                align="left"
                                placeholder="选择日期"
                                type="date"
                                v-model="searchMap.createTime"
                        >
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button @click="fetchData" type="primary">查询</el-button>
                    </el-form-item>
                </el-form>
            </div>

            <el-table :data="tableData" border style="width: 100%">
                <el-table-column
                        align="center"
                        label="订单编号"
                        prop="id">
                </el-table-column>
                <el-table-column
                        align="center"
                        label="提交时间"
                        prop="createTime">
                </el-table-column>
                <el-table-column
                        align="center"
                        label="用户名称"
                        prop="username">
                </el-table-column>
                <el-table-column
                        align="center"
                        label="收货人"
                        prop="receiverContact">
                </el-table-column>
                <el-table-column
                        align="center"
                        label="订单金额">
                    <template slot-scope="scope">
                        ￥{{scope.row.payMoney}}
                    </template>
                </el-table-column>
                <el-table-column
                        align="center"
                        label="订单状态">
                    <template slot-scope="scope">
                        {{scope.row.orderStatus===0?'待付款':
                        scope.row.orderStatus===1?'待发货':
                        scope.row.orderStatus===2?'已发货':
                        scope.row.orderStatus===3?'已完成':
                        scope.row.orderStatus===4?'已关闭':''}}
                    </template>
                </el-table-column>
                <el-table-column
                        align="center"
                        label="交易关闭时间"
                        prop="closeTime">
                </el-table-column>
                <el-table-column
                        align="center"
                        label="操作">
                    <template slot-scope="scope">
                        <el-button @click="edit(scope.row.id)" size="mini" size="small" type="primary">查看订单</el-button>
                        <el-button @click="dele(scope.row.id)" size="mini" size="small" type="danger">确认收货</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        :current-page.sync="currentPage"
                        :page-size="size"
                        :page-sizes="[10, 20, 30, 40]"
                        :total="total"
                        @current-change="fetchData"
                        @size-change="fetchData"
                        class="pagiantion"
                        layout="total, sizes, prev, pager, next, jumper">
                </el-pagination>
            </div>
            <div class="add-form">
                <!--弹出窗口-->
                <el-dialog :visible.sync="formVisible" title="编辑">
                    <el-form label-width="80px">

                        <el-form-item>
                            <el-button @click="save()" type="primary">保存</el-button>
                            <el-button @click="formVisible = false">关闭</el-button>
                        </el-form-item>
                    </el-form>
                </el-dialog>
            </div>

        </div>
    </div>


</div>
</body>
<script src="/js/vue.js"></script>
<script src="/js/axios.js"></script>
<script src="/js/elementui.js"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                tableData: [],
                currentPage: 1,
                total: 10,
                size: 10,
                searchMap: {
                    "consignStatus": "1"
                },
                pojo: {},
                formVisible: false,
                //提交时间筛选
                pickerOptions: {
                    disabledDate(time) {
                        return time.getTime() > Date.now();
                    },
                    shortcuts: [{
                        text: '今天',
                        onClick(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '昨天',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周前',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                }
                //提交时间筛选 --end
            }
        },
        created() {
            this.fetchData();
        },
        methods: {
            fetchData() {
                axios.post(`/order/findPage.do?page=${this.currentPage}&size=${this.size}`, this.searchMap).then(response => {
                    this.tableData = response.data.rows;
                    this.total = response.data.total;
                });
            },
            save() {
                // this.pojo.image= this.imageUrl; //如页面有图片上传功能放开注释
                axios.post(`/order/${this.pojo.id == null ? 'add' : 'update'}.do`, this.pojo).then(response => {
                    this.fetchData(); //刷新列表
                    this.formVisible = false;//关闭窗口
                });
            },
            edit(id) {
                this.formVisible = true // 打开窗口
                // 调用查询
                axios.get(`/order/findById.do?id=${id}`).then(response => {
                    this.pojo = response.data;
                    // this.imageUrl=this.pojo.image //显示图片  如页面有图片上传功能放开注释
                })
            },
            dele(id) {
                this.$confirm('确定要删除此记录吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get(`/order/delete.do?id=${id}`).then(response => {
                        this.fetchData(); //刷新列表
                    })
                })
            },

        }
    })
</script>
</html>
